package com.frostmourne.mxsattributeinventory.hooks;

import com.frostmourne.mxsattributeinventory.MXSAttributeInventory;
import com.frostmourne.mxsattributeinventory.utils.FileUtils;
import com.gitee.mxstars.builder.InventoryBuilder;
import eos.moe.armourers.api.DragonAPI;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DAHook {

    public static Map<Player,Map<String, List<ItemStack>>> playerArmourersMap = new HashMap<>();

    public static void refreshArmourers(Player player,String invName){
        if (!MXSAttributeInventory.inventoryMap.containsKey(invName)){
            return;
        }
        if (!MXSAttributeInventory.enableMap.get(invName).contains("DragonArmourers")){
            return;
        }
        Map<String,List<ItemStack>> playerItemsMap = new HashMap<>();
        if (playerArmourersMap.containsKey(player)){
            playerItemsMap = playerArmourersMap.get(player);
        }
        List<ItemStack> items = new ArrayList<>();
        for (int i = 0; i < MXSAttributeInventory.inventoryMap.get(invName).getInv().getSize(); i++) {
            ItemStack item = FileUtils.getItemByNameAndSlot(player,invName,i);
            if (item != null && item.hasItemMeta() && item.getItemMeta().hasLore()){
                items.add(item);
            }
        }
        playerItemsMap.put(invName,items);

        playerArmourersMap.put(player,playerItemsMap);

        DragonAPI.updatePlayerSkin(player);
    }
}
